<!DOCTYPE html>
<html>
<head>
    <title>Acura 文件测试</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .result { margin: 10px 0; padding: 10px; border-radius: 4px; }
        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
        .info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
    </style>
</head>
<body>
    <h1>Acura ILX 2016 DBC 文件测试</h1>
    <div id="results"></div>
    
    <script src="dbc-parser.js"></script>
    <script>
        function addResult(message, type = 'info') {
            const div = document.createElement('div');
            div.className = `result ${type}`;
            div.textContent = message;
            document.getElementById('results').appendChild(div);
        }

        // 模拟 acura_ilx_2016_nidec.dbc 文件的前几行
        const acuraContent = `VERSION ""


NS_ : 
\tNS_DESC_
\tCM_
\tBA_DEF_
\tBA_
\tVAL_
\tCAT_DEF_
\tCAT_
\tFILTER
\tBA_DEF_DEF_
\tEV_DATA_
\tENVVAR_DATA_
\tSGTYPE_
\tSGTYPE_VAL_
\tBA_DEF_SGTYPE_
\tBA_SGTYPE_
\tSIG_TYPE_REF_
\tVAL_TABLE_
\tSIG_GROUP_
\tSIG_VALTYPE_
\tSIGTYPE_VALTYPE_
\tBO_TX_BU_
\tBA_DEF_REL_
\tBA_REL_
\tBA_DEF_DEF_REL_
\tBU_SG_REL_
\tBU_EV_REL_
\tBU_BO_REL_
\tSG_MUL_VAL_

BS_:

BU_: ADAS RADAR NEO XXX


BO_ 768 VEHICLE_STATE: 8 ADAS
 SG_ SET_ME_XF9 : 7|8@0+ (1,0) [0|255] "" Vector__XXX
 SG_ VEHICLE_SPEED : 15|8@0+ (1,0) [0|255] "kph" Vector__XXX

BO_ 769 VEHICLE_STATE2: 8 ADAS
 SG_ SET_ME_0F18510 : 7|28@0+ (1,0) [0|268435455] "" Vector__XXX
 SG_ SET_ME_25A0000 : 27|28@0+ (1,0) [0|268435455] "" Vector__XXX`;

        addResult('开始测试 Acura ILX 2016 DBC 文件...');
        
        // 测试词法分析器
        addResult('=== 词法分析器测试 ===');
        try {
            const tokenizer = new DBCTokenizer(acuraContent);
            
            addResult('前 20 个 tokens:');
            for (let i = 0; i < 20; i++) {
                const token = tokenizer.getNextToken();
                if (token.type === TokenType.Eof) {
                    addResult(`Token ${i + 1}: EOF`, 'info');
                    break;
                }
                addResult(`Token ${i + 1}: ${token.type} | "${token.image}"`, 'info');
            }
            
        } catch (error) {
            addResult(`词法分析错误: ${error.message}`, 'error');
        }

        // 测试完整解析
        addResult('=== 完整解析测试 ===');
        try {
            const result = parseDBCContent(acuraContent, 'acura_ilx_2016_nidec.dbc');
            addResult(`✓ 解析成功!`, 'success');
            addResult(`版本: "${result.version}"`, 'info');
            addResult(`节点数: ${result.nodes.length}`, 'info');
            addResult(`帧数: ${result.frames.length}`, 'info');
            addResult(`警告数: ${result.warnings.length}`, 'info');
            
            if (result.warnings.length > 0) {
                addResult('警告信息:', 'warning');
                result.warnings.forEach(warning => {
                    addResult(`  行 ${warning.line}: ${warning.message}`, 'warning');
                });
            }
            
            if (result.frames.length > 0) {
                addResult('帧信息:', 'info');
                result.frames.forEach((frame, index) => {
                    addResult(`  帧 ${index + 1}: ${frame.name} (ID: 0x${frame.canId.toString(16)}, 信号数: ${frame.signals.length})`, 'info');
                });
            }
            
        } catch (error) {
            addResult(`✗ 解析失败: ${error.message}`, 'error');
        }

        addResult('测试完成!', 'info');
    </script>
</body>
</html> 